namespace BM.Tools.WebControls.MForm.Navigation.Predicates
{
    using BM.Tools.WebControls.MForm.Navigation.XPath.Predicates;

    /// <summary>
    /// A navigator for the <see cref="NegationPredicate" /> predicate locator.
    /// </summary>
    /// <typeparam name="T">
    /// The type of the navigable object.
    /// </typeparam>
    public class NegationPredicateNavigator<T> : PredicateNavigator<T, NegationPredicate>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NegationPredicateNavigator{T}"/> class. 
        /// </summary>
        /// <param name="parent">
        /// The parent.
        /// </param>
        /// <param name="locator">
        /// The locator.
        /// </param>
        public NegationPredicateNavigator(INavigator<T> parent, NegationPredicate locator) : base(parent, locator)
        {
        }

        /// <summary>
        /// Tests the navigable object against the negation of the <see cref="NegationPredicate"/> content predicate.
        /// </summary>
        /// <param name="navigable">
        /// The navigable.
        /// </param>
        /// <returns>
        /// returns negation of the <see cref="NegationPredicate"/> content predicate
        /// </returns>
        public override bool Matches(T navigable)
        {
            var predicateNavigator = PredicateNavigatorFactory<T>.Create(this, Locator.Content);
            return !predicateNavigator.PredicateFunction.Invoke(navigable);
        }
    }
}